<?php
namespace app\common\service\impl;
use app\common\client\CheckIotClient;
use app\common\service\CheckService;
use think\facade\Log;

class CheckServiceImpl implements CheckService
{
    protected $checkIotClient;
    
    public function __construct(CheckIotClient $checkIotClient)
    {
        $this->checkIotClient = $checkIotClient;
    }
    
    public function check(array $data)
    {
        $url = "";
        switch ($data['machine']) {
            case 1:
                $url = "http://120.79.71.83:8091";
            break;
            case 2:
                $url = "http://47.107.252.37:8080";
                break;
            case 3:
                $url = "http://47.107.12.217:8080";
                break;
            default:
                ;
            break;
        }
        
        switch ($data['step']) {
            case 1:
                $res = $this->checkIotClient->heartCheck($url);
            break;
            case 2:
                $res = $this->checkIotClient->testIotClient($url);
                break;
            case 3:
                $res = $this->checkIotClient->testMongo($url);
                break;
            case 4:
                $res = $this->checkIotClient->testRedis($url);
                break;
            default:
                ;
            break;
        }
        
        if($res === false){
            return false;
        }
        if($res['code'] == 0){
            return true;
        }else{
            Log::record("[ 检测失败 ]".$res['msg']);
            return false;
        }
        
        
    }

   
}

